package com.hardy.data_structure;

/**
 * Author: Hardy
 * Date:   2019/3/21
 * Description:
 **/
public abstract class Linked {

    protected Node root;

    protected int length;

    public Linked() {
    }

    // 追加元素
    public abstract void add(int val);

    // 删除元素
    public abstract void del(int val);

    // 插入位置元素
    public abstract void insert(int idx, int val);

    // 删除位置元素
    public abstract void remove(int idx);

    // 反转
    public abstract void reverse();

    // 打印信息
    public void print() {
        System.out.println("长度: " + length);

        StringBuilder sb = new StringBuilder("[");

        if (root != null) {
            Node node = root;
            while (true) {
                sb.append(node.val);
                if (node.next == null) break;

                sb.append(",");
                node = node.next;
            }
        }
        sb.append("]");

        System.out.println("内容: " + sb.toString());
        System.out.println("---------------------------------------");
    }
}
